package com.nvwa.mvp.validated.form;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.*;
import java.util.Date;

/**
 * UserForm 类。
 *
 * @author wangjing
 * @date 2024-12-27 [wangjing] 创建。
 */

@Getter
@Setter
@NoArgsConstructor
public class UserForm {
    @NotBlank(message = "姓名不能为空")
    private String name;
    @Range(min = 1, max = 100, message = "年龄必须在1-100岁之间")
    private Integer age;
    @Past(message = "生日必须是过去的时间")
    private Date birthDay;
    private String gender;
    @Email(message = "邮箱格式不正确")
    private String email;
    @NotNull(message = "地址不能为NULL")
    private String address;
    @Length(min = 6, max = 20, message = "密码长度必须在6-20位之间")
    private String password;
    @Length(min = 6, max = 20, message = "密码长度必须在6-20位之间")
    private String confirmPassword;
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    private String phoneNum;
    @NotEmpty(message = "爱好不能为空")
    private String[] hobbies;

    @AssertTrue(message = "性别不正确")
    public boolean isGenderValid() {
        return "男".equals(gender) || "女".equals(gender);
    }
    @AssertTrue(message = "两次密码不一致")
    public boolean isPasswordValid() {
        return password.equals(confirmPassword);
    }
}
